//
//	(c) 2009 Andrew Kalmacky
//

#ifndef _AK_PTR_VECTOR_H_
#define _AK_PTR_VECTOR_H_

#include "ltm.h"
#include "../logger/logger.h"
#include "ltm_vector.h"

namespace ak { namespace ltm
{
    typedef vector< master<Object> > master_vector_base;

    template <typename T>
    class master_vector: public master_vector_base
    {
    public:
        typedef master<T>* iterator;
        typedef const master<T>* const_iterator;

        explicit master_vector(size_t size = 0)
            : master_vector_base(size)
        {
        }

        master_vector(const master_vector<T>& src)
            : master_vector_base(src)
        {
        }

                master_vector<T>& operator=(const master_vector<T>& src)
                {
                    if (this != &src)
                    {
                        this->~master_vector();
                        new(this) master_vector<T>(src);
                    }
                    return *this;
                }

        iterator begin() no_throw
        {
            return reinterpret_cast<iterator>(master_vector_base::begin());
        }
        const_iterator begin() const no_throw
        {
            return reinterpret_cast<const_iterator>(master_vector_base::begin());
        }
        iterator end() no_throw
        {
            return reinterpret_cast<iterator>(master_vector_base::end());
        }
        const_iterator end() const no_throw
        {
            return reinterpret_cast<const_iterator>(master_vector_base::end());
        }
                iterator erase(const iterator& at)
        {
                    return reinterpret_cast<iterator>(master_vector_base::erase(reinterpret_cast<const master_vector_base::iterator&>(at)));
        }
        iterator erase(size_t at)
        {
            return erase(begin() + at);
        }
        iterator erase(iterator from, iterator to)
        {
            return reinterpret_cast<iterator>(master_vector_base::erase(
                reinterpret_cast<master_vector_base::iterator&>(from),
                reinterpret_cast<master_vector_base::iterator&>(to)));
        }
        iterator insert(iterator at)
        {
            return reinterpret_cast<iterator>(master_vector_base::insert(
                reinterpret_cast<master_vector_base::iterator&>(at)));
        }
        iterator insert(size_t at)
        {
            return insert(begin() + at);
        }
        iterator insert(iterator at, const pin<T>& p)
        {
            return reinterpret_cast<iterator>(
                    master_vector_base::insert(reinterpret_cast<master_vector_base::iterator>(at), p));
        }
        iterator insert(size_t at, const pin<T>& p)
        {
            return insert(begin() + at, p);
        }
        void move_items(iterator dst, iterator src_from, iterator src_to)
        {
            master_vector_base::move_items(
                reinterpret_cast<master_vector_base::iterator&>(dst),
                reinterpret_cast<master_vector_base::iterator&>(src_from),
                reinterpret_cast<master_vector_base::iterator&>(src_to));
        }
        master<T>& push_back(const pin<T>& p)
        {
            return reinterpret_cast<master<T>&>(master_vector_base::push_back(p));
        }
        master<T>& push_back()
        {
            return reinterpret_cast<master<T>&>(master_vector_base::push_back());
        }
        master<T>& back()
        {
            return reinterpret_cast<master<T>&>(master_vector_base::back());
        }
        master<T>& push_front(const pin<T>& p)
        {
            return reinterpret_cast<master<T>&>(master_vector_base::push_front(p));
        }
        master<T>& push_front()
        {
            return reinterpret_cast<master<T>&>(master_vector_base::push_front());
        }
        master<T>& front()
        {
            return reinterpret_cast<master<T>&>(master_vector_base::front());
        }
        master<T>& operator[] (size_t index)
        {
            return reinterpret_cast<master<T>&>(master_vector_base::operator[](index));
        }
        master<T>& at(size_t index)
        {
            return reinterpret_cast<master<T>&>(master_vector_base::at(index));
        }
        const master<T>& operator[] (size_t index) const
        {
            return reinterpret_cast<const master<T>&>(master_vector_base::operator[](index));
        }
        const master<T>& at(size_t index) const
        {
            return reinterpret_cast<const master<T>&>(master_vector_base::at(index));
        }
    };
}}

#endif // _AK_PTR_VECTOR_H_
